home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 1998 February / PCM_9802.iso / programi / director / data.z / Behavior Library.cst / 00030_Script_Net Preload Net Thing < prev    next >
Text File  |  1997-05-09  |  5KB  |  153 lines

  1. -- Net preloadNet Thing
  2.  
  3.  
  4. -- preloadNetThingBuddy Behavior script
  5. -- 2/13/97 Chris Walcott
  6.  
  7. -- This behavior can be used to as a general purpose preloadNetThing script.
  8. -- The behavior is assigned to a frame Script.  
  9. -- The required custom properties are:
  10.  
  11. -- "Channel number of field" - this is the field that will contain the list
  12. -- of URL's that are to be preloaded. Use the Score channel number of the field.
  13. -- "Debug" - If TRUE, status lines will print to the message window.
  14. -- "AutoLoad URL" - If set to "AutoLoad", a preloadNetThing will be performed on
  15. -- the URL provided in the next property field.  If set to "Manual", you will need 
  16. -- to perform the gotoNetPage operation yourself.
  17. -- "Target URL" -  if AutoLoad is set, a gotoNetPage operation will be performed 
  18. -- on this URL.
  19.  
  20.  
  21. property pListURLs         -- field containing URL's to preload
  22. property pDebug            -- field containing URL's to preload
  23. property pAutoLoad         -- field containing URL's to preload
  24. property pURL              -- which URL is called if AutoLoad is set
  25. property pInitializeDone   -- field containing URL's to preload
  26.  
  27. property pWaitingList          -- list of URL's waiting to be retrieved
  28. property pDispatchedListURL    -- list of preloaded URL's
  29. property pDispatchedListNetID  -- list of preloaded URL net ID's
  30.  
  31.  
  32.  
  33. on getPropertyDescriptionList
  34.   set description = [:]
  35.   
  36.   addprop description, #pListURLs, [#default: member 1, #format: #field, ¼
  37.   #comment: "Member name of URL list:"]
  38.   
  39.   addprop description, #pDebug, [#default: 0, #format:#boolean,¼
  40.  #comment: "Debug:"]
  41.   
  42.   addprop description, #pAutoLoad, [#default: #AutoLoad, #format:#symbol,¼
  43.  #comment: "AutoLoad URL:", #range: [#AutoLoad, #Manual]]
  44.   
  45.   addprop description, #pURL, [#default: "http://", #format: #string, ¼
  46.   #comment: "Target URL for AutoLoad:"]
  47.   
  48.   return description
  49. end
  50.  
  51. on beginSprite me
  52.   
  53.   set pInitializeDone = FALSE
  54. end
  55.  
  56.  
  57. on exitFrame me
  58.   
  59.   if  NOT pInitializeDone = TRUE then
  60.     initializeNetList
  61.     cursor 4
  62.     set pInitializeDone = TRUE
  63.   end if
  64.   
  65.   if NetDoneList() > 0 then
  66.     go to the frame
  67.   else
  68.     if pAutoLoad = TRUE then
  69.       cursor 0
  70.       gotoNetPage pURL
  71.     else   
  72.       go to frame "done"
  73.       cursor 0
  74.     end if
  75.   end if
  76.   
  77. end
  78.  
  79.  
  80. on initializeNetList me
  81.   
  82.   -- initialize the lists
  83.   set pWaitingList = []
  84.   set pDispatchedListURL = []
  85.   set pDispatchedListNetID = []
  86.   repeat with i = 1 to the lineCount of member pListURLs
  87.     set theLine = line i of field pListURLs
  88.     append( pWaitingList, theLine)
  89.   end repeat
  90.   
  91.   if pDebug = TRUE then
  92.     put "List of assets to preload" & RETURN & pWaitingList & RETURN
  93.   end if
  94.   
  95.   
  96. end
  97.  
  98.  
  99. on netDoneList me
  100.   
  101.   -- check the dispatch list for assest that have arrived
  102.   repeat with iListAsset = 1 to count( pDispatchedListURL )
  103.     -- if the asset has arrived
  104.     if NetDone( getAt( pDispatchedListNetID, iListAsset ) ) then
  105.       if pDebug = TRUE then
  106.         put "Asset Received:" & getAt( pDispatchedListURL, iListAsset )
  107.       end if
  108.       -- remove if from the dispatch list
  109.       deleteAt pDispatchedListURL, iListAsset
  110.       deleteAt pDispatchedListNetID, iListAsset
  111.     end if
  112.   end repeat
  113.   
  114.   -- check the dispatch and waiting list: how many things
  115.   -- can we preload?  Current stream limit is set to 4
  116.   set iCountDispatch to min( count( pWaitingList ), 4 - count( pDispatchedListURL ) )
  117.   repeat with iFreeSpot = 1 to iCountdispatch
  118.     
  119.     -- start the  preloadNetThing operation on the next waiting asset
  120.     set getMe = getAt( pWaitingList, 1 )
  121.     if pDebug = TRUE then
  122.       put "Asset Preloading" getMe
  123.     end if
  124.     preloadNetThing getMe
  125.     
  126.     -- move the asset to the dispatched list
  127.     append pDispatchedListURL, getAt( pWaitingList, 1 )
  128.     append pDispatchedListNetID, getLatestNetID()
  129.     -- remove the asset from the waiting list
  130.     deleteAt pWaitingList, 1
  131.   end repeat
  132.   
  133.   -- check the dispatch list for assest that have arrived
  134.   set netDoneListCount = count( pDispatchedListURL ) + count( pWaitingList )
  135.   if pDebug = TRUE then
  136.     put "Assets remaining to process:" netDoneLIstCount
  137.   end if
  138.   return netDoneListCount
  139.   
  140. end
  141.  
  142. on getBehaviorDescription
  143.   return ¼
  144. "Preloads a file from the internet to the disk cache so it can be used later without a download delay. Loads the file while the current movie continues playing. After an item is preloaded, it can be displayed immediately because it is taken from the local browserÆs cache rather than from the network. "& RETURN & ¼
  145. "PARAMETERS:" & RETURN & ¼
  146. "ò Channel Number of Field - this is the field that will contain the list"
  147.   -- of URL's that are to be preloaded. Use the Score channel number of the field.
  148.   -- "Debug" - If TRUE, status lines will print to the message window.
  149.   -- "AutoLoad URL" - If set to "AutoLoad", a preloadNetThing will be performed on
  150.   -- the URL provided in the next property field.  If set to "Manual", you will need 
  151.   -- to perform the gotoNetPage operation yourself.
  152.   -- "Target URL" -  if AutoLoad is set, a gotoNetPage operation will be performed 
  153.   -- on this URL.